package com.dhnsoft.boot.core.service;

import com.dhnsoft.boot.core.entity.User;
import com.dhnsoft.boot.core.event.LoginSuccessEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Service;

/**
 * @author dhn
 * @version 1.0
 * @date 2023-09-05 17:27
 * @Desc
 */
@Service
public class AccountService implements ApplicationListener<LoginSuccessEvent> {
    public void addAccountService(String username){
        System.out.println("系统随机发放了优惠券给:"+username);
    }

    @Override
    public void onApplicationEvent(LoginSuccessEvent event) {
        System.out.println("======AccountService 收到事件=======");
        User source = (User) event.getSource();
        addAccountService(source.getUsername());
    }
}
